# -*- coding: utf-8 -*-
import uuid

import datetime
from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative import declared_attr


class BaseModel(object):
    created_at = Column(DateTime, default=lambda: datetime.datetime.now())
    updated_at = Column(DateTime, onupdate=lambda: datetime.datetime.now())

    metadata =None

    @declared_attr
    def __tablename__(cls):
        return cls.__name__.lower()

    def as_dict(self):
        d = {}
        for c in self.__table__.columns:
            d[c.name] = self[c.name]
        return d


Base = declarative_base(cls=BaseModel)


def generate_dashed_uuid():
    """Creates a random uuid string.
    """
    return str(uuid.uuid4())


def generate_hex_uuid():
    return uuid.uuid4().hex


class Worker(Base):
    """
    Worker Model
    """

    __tablename__ = 'workers'

    id = Column(String(32), primary_key=True, default=generate_hex_uuid)
    host = Column(String(64), nullable=False, unique=True)
